<%@ page import="java.net.URLDecoder" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    Cookie[] cookies = request.getCookies();
    String username="";
%>

<html>
<head>
    <title>用户管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/bootstrap.min.js"></script>
    <%--<style>
        body{
            width: 100%;
        }
        .sb{
            position: absolute;
            left: 50%;
            transform: translate(-50%,-50%);
        }
        img{
            width: 190px;
            height: 240px;
        }

        td{
            line-height: 240px;
        }

        .dropdown-toggle{
            border: none;
            font-size: 16px;
            font-weight: bold;
            margin-bottom: -6px;
            margin-left: -14px;
            background-color: #28FF28;
        }
        #sbbbb{
            position: sticky;
            top: 0;
            background-color: #28FF28;
        }

    </style>

    <script>

        window.onload = function () {
            var btn01 = document.getElementById("btn01");
            var btn02 = document.getElementById("btn02");
            btn01.onclick = function () {
                if (${user.pageNum >= user.pages}){
                    var ssr = document.getElementById("ssr");
                    ssr.innerHTML = "最后一页了熙哥";
                    var time = setInterval(function () {
                        ssr.innerHTML = " ";
                        clearInterval(time);
                    },2000);
                    btn01.href = "#";
                }


            }
            btn02.onclick = function () {
                if (${user.isFirstPage}) {
                    var ssr = document.getElementById("ssr");
                    ssr.innerHTML = "第一页了熙哥";
                    var time = setInterval(function () {
                        ssr.innerHTML = " ";
                        clearInterval(time);
                    },2000);
                    btn02.href = "#";
                }
            }
        }

    </script>--%>

    <script>

        (function($){
            $(window).load(function(){

                $("a[rel='load-content']").click(function(e){
                    e.preventDefault();
                    var url=$(this).attr("href");
                    $.get(url,function(data){
                        $(".content .mCSB_container").append(data); //load new content inside .mCSB_container
                        //scroll-to appended content
                        $(".content").mCustomScrollbar("scrollTo","h2:last");
                    });
                });

                $(".content").delegate("a[href='top']","click",function(e){
                    e.preventDefault();
                    $(".content").mCustomScrollbar("scrollTo",$(this).attr("href"));
                });

            });
        })(jQuery);
    </script>
</head>
<body>
​<jsp:include page="../book/header.jsp"/>
<section class="rt_wrap content mCustomScrollbar">
    <div class="rt_content">
        <div class="page_title">
            <h2 class="fl">会员列表</h2>
            <a href="${pageContext.request.contextPath}/user/toaddUser" class="fr top_rt_btn add_icon">添加新会员</a>
        </div>
        <section class="mtb">
            <select class="select">
                <option>会员等级</option>
                <option>普通会员</option>
                <option>管理员</option>
            </select>
            <input type="text" class="textbox textbox_225" placeholder="输入会员号/手机/电子邮件查询..."/>
            <input type="button" value="查询" class="group_btn"/>
        </section>
        <table class="table">
            <tr>
                <th>Id</th>
                <th>会员头像</th>
                <th>会员账号</th>
                <th>密码</th>
                <th>用户昵称</th>
                <th>创建时间</th>
                <th>会员等级</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${user.list}" var="user">
                <tr>
                    <td class="center">${user.id}</td>
                    <td class="center"><img src="${user.avatar}" width="50" height="50"/></td>
                    <td>${user.userName}</td>
                    <td class="center">${user.password}</td>
                    <td class="center">${user.nickname}</td>
                    <td class="center">${user.createTime}</td>
                    <td class="center"><c:if test="${user.type == 0}">普通会员</c:if>
                        <c:if test="${user.type == 1}">管理员</c:if>
                        <c:if test="${user.type == 2}">超级管理员</c:if></td>
                    <td class="center">
                        <c:set var="id" value="${sessionScope.user.type}"/>
                        <c:if test="${id > user.type}">
                            <a href="user_detail.html" title="编辑" class="link_icon">&#101;</a>
                            <a href="#" title="删除" class="link_icon">&#100;</a>
                        </c:if>
                        <c:if test="${user.type >= id}">
                            权限不够，无法操作
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <aside class="paging">
            <a href="${requestScope['javax.servlet.forward.request_uri']}?name=<%=request.getAttribute("key")%>&pn=${user.pageNum-1}" id="btn02">上一页</a>
            <c:forEach begin="1" end="${user.pages}" var="i">
                <a href="${requestScope['javax.servlet.forward.request_uri']}?name=<%=request.getAttribute("key")%>&pn=${i}">${i}</a>
            </c:forEach>
            <a href="${requestScope['javax.servlet.forward.request_uri']}?name=<%=request.getAttribute("key")%>&pn=${user.pageNum+1}" id="btn01">下一页</a>
        </aside>
    </div>
</section>
<%--<div class="container">
    ​
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>用户列表 —— 显示所有用户</small>
                </h1>
                <form action="${pageContext.request.contextPath}/user/queryUserByUserName" method="get">
                    <input type="text" name="userName" id="name" placeholder="请输入要查询的用户" value="${key}"/>
                    <input type="submit" id="btn04">
                </form>
            </div>
        </div>
    </div>
    ​
    <div class="row">
        <div class="col-md-4 column">
            <a class="btn btn-primary"href="${pageContext.request.contextPath}/user/toaddUser">新增</a>
        </div>
    </div>
    ​
    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-hover table-striped">
                <thead id="sbbbb">
                <tr>
                    <th>用户头像</th>
                    <th>用户名</th>
                    <th>用户密码</th>
                    <th>用户昵称</th>
                    <th class="dsb">
                        <div class="dropdown">
                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                用户类型
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                                <li><a href="${pageContext.request.contextPath}/user/allUser">全部</a></li>
                                <c:forEach items="${type}" var="type">
                                    <li><a href="${pageContext.request.contextPath}/user/queryUserByType?type=${type}">${type}</a></li>
                                </c:forEach>
                            </ul>
                        </div>
                    </th>
                    <th>用户创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                ​
                <tbody>
                <c:forEach var="user" items="${user.list}">
                    <tr>
                        <td><img src="${user.avatar}" alt="${user.userName}"></td>
                        <td>${user.userName}</td>
                        <td>${user.password}</td>
                        <td>${user.nickname}</td>
                        <td><c:choose><c:when test="${user.type==1}">普通用户</c:when><c:otherwise>管理员</c:otherwise></c:choose></td>
                        <td>${user.createTime}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/user/toupdateUser?id=${user.id}">更改</a> |
                            <a href="${pageContext.request.contextPath}/user/deleteUser?id=${user.id}">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>

            </table>
        </div>
    </div>
</div>

<div class="sb">
    <nav aria-label="Page navigation">
        <ul class="pagination col-md-12 col-lg-12 column">
            <li>
                <a href="${requestScope['javax.servlet.forward.request_uri']}?userName=<%=request.getAttribute("key")%>&pn=${user.pageNum-1}" id="btn02" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
            <c:forEach begin="1" end="${user.pages}" var="i">
                <li><a href="${requestScope['javax.servlet.forward.request_uri']}?userName=<%=request.getAttribute("key")%>&pn=${i}">${i}</a></li>
            </c:forEach>
            <li>
                <a href="${requestScope['javax.servlet.forward.request_uri']}?userName=<%=request.getAttribute("key")%>&pn=${user.pageNum+1}" id="btn01" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>
</div>
<p id="ssr"></p>

</div>

</div>--%>
</body>
</html>